package com.sicc.prototype.controller;

import java.text.DateFormat;
import java.util.Date;
import java.util.Locale;

import javax.annotation.Resource;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.sicc.prototype.dto.ProtoTypeDto;
import com.sicc.prototype.service.ProtoTypeService;

// TODO: Auto-generated Javadoc
/**
 * Handles requests for the application home page.
 */
@Controller
public class ProtoTypeController {  
	  
	/** The Constant logger. */
	private static final Logger logger = LoggerFactory.getLogger(ProtoTypeController.class);
	
	

	/** The proto type service. */
	
	@Resource(name = "protoTypeService")
	private ProtoTypeService protoTypeService;
	
	/**
	 * Simply selects the home view to render by returning its name.
	 *
	 * @param locale the locale
	 * @param model the model
	 * @return the string
	 */
	@RequestMapping(value = "/", method = RequestMethod.GET)
	public String home(Locale locale, Model model) {
		logger.info("Welcome home! The client locale is {}.", locale);
		
		Date date = new Date();
		DateFormat dateFormat = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG, locale);
		
		String formattedDate = dateFormat.format(date);
		
		model.addAttribute("serverTime", formattedDate );
		
		ProtoTypeDto dto = new ProtoTypeDto();
		dto.setEname("이명박");
		model.addAttribute("protoTypeDto", protoTypeService.selectOne(dto));
		
		return "home";
	}
	
	/**
	 * Simply selects the home view to render by returning its name.
	 *
	 * @param model the model
	 * @return the string
	 */
	@RequestMapping(value = "/list", method = RequestMethod.GET)
	public String list( Model model) {
		model.addAttribute("protoTypeList", protoTypeService.selectList());
		return "list";
	}
	
}
